GetValueElseAdd Method

Wintellect PowerCollections

Collapse imageExpand ImageCollapseAll imageExpandAll imageDropDown imageDropDownHover imageCopy imageCopyHover image
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Finds a key in the dictionary. If the dictionary already contains a key equal to the passed key, then the existing value is returned via value. If the dictionary doesn't contain that key, then value is associated with that key.

Namespace: Wintellect.PowerCollections
Assembly:  PowerCollections (in PowerCollections.dll)

Syntax

C#
public bool GetValueElseAdd(
	TKey key,
	ref TValue value
)
Visual Basic (Declaration)
Public Function GetValueElseAdd ( _
	key As TKey, _
	ByRef value As TValue _
) As Boolean
Visual C++
public:
bool GetValueElseAdd (
	TKey key, 
	TValue% value
)

Parameters

key
TKey
The new key.
value
TValue%
The new value to associated with that key, if the key isn't present. If the key was present, returns the exist value associated with that key.

Return Value

True if key was already present, false if key wasn't present (and a new value was added).

Remarks

between keys is determined by the comparison instance or delegate used to create the dictionary.

This method takes time O(log N), where N is the number of keys in the dictionary. If a value is added, It is more efficient than calling TryGetValue followed by Add, because the dictionary is not searched twice.

See Also